Correctly set up paths when packaging
authorAlex Crichton <alex@alexcrichton.com>
Thu, 5 Mar 2015 23:29:05 +0000 (15:29 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 6 Mar 2015 18:29:20 +0000 (10:29 -0800)
A synthetic "Package" is being created as part of this step but its paths were
pointing at the original root, not the unpacked tarball for testing. This meant
that some assumptions about the relative-ness of paths didn't quite end up
working out.

Closes #1382

src/cargo/ops/cargo_package.rs
src/cargo/sources/path.rs
src/cargo/util/to_semver.rs

index 426181a1a00d13b946e5d06aa3b189dbdd5e3b7e..6bf4a931a0cda021b40eae8b017771818ac3df97 100644 (file)
@@ -6,8 +6,7 @@ use tar::Archive;
 use flate2::{GzBuilder, Compression};
 use flate2::read::GzDecoder;
 
-use core::source::{Source, SourceId};
-use core::Package;
+use core::{Source, SourceId, Package, PackageId};
 use sources::PathSource;
 use util::{self, CargoResult, human, internal, ChainError, Config};
 use ops;
@@ -160,16 +159,23 @@ fn run_verify(config: &Config, pkg: &Package, tar: &Path)
     // When packages are uploaded to the registry, all path dependencies are
     // implicitly converted to registry-based dependencies, so we rewrite those
     // dependencies here.
+    //
+    // We also be sure to point all paths at `dst` instead of the previous
+    // location that the package was original read from. In locking the
+    // `SourceId` we're telling it that the corresponding `PathSource` will be
+    // considered updated and won't actually read any packages.
     let registry = try!(SourceId::for_central(config));
+    let precise = Some("locked".to_string());
+    let new_src = try!(SourceId::for_path(&dst)).with_precise(precise);
+    let new_pkgid = try!(PackageId::new(pkg.name(), pkg.version(), &new_src));
     let new_summary = pkg.summary().clone().map_dependencies(|d| {
         if !d.source_id().is_path() { return d }
         d.set_source_id(registry.clone())
     });
     let mut new_manifest = pkg.manifest().clone();
-    new_manifest.set_summary(new_summary);
+    new_manifest.set_summary(new_summary.override_id(new_pkgid));
     new_manifest.set_target_dir(dst.join("target"));
-    let new_pkg = Package::new(new_manifest, &manifest_path,
-                               pkg.package_id().source_id());
+    let new_pkg = Package::new(new_manifest, &manifest_path, &new_src);
 
     // Now that we've rewritten all our path dependencies, compile it!
     try!(ops::compile_pkg(&new_pkg, &ops::CompileOptions {
index 11352770e541f6dffe920cfedeb452040e0b6d79..8ff39be6353a400485d01f79e757f2bd00eac367 100644 (file)
@@ -58,8 +58,19 @@ impl<'a, 'b> PathSource<'a, 'b> {
     }
 
     pub fn read_packages(&self) -> CargoResult<Vec<Package>> {
+
         if self.updated {
             Ok(self.packages.clone())
+        } else if self.id.is_path() && self.id.precise().is_some() {
+            // If our source id is a path and it's listed with a precise
+            // version, then it means that we're not allowed to have nested
+            // dependencies (they've been rewritten to crates.io dependencies)
+            // In this case we specifically read just one package, not a list of
+            // packages.
+            let path = self.path.join("Cargo.toml");
+            let (pkg, _) = try!(ops::read_package(&path, &self.id,
+                                                  self.config));
+            Ok(vec![pkg])
         } else {
             ops::read_packages(&self.path, &self.id, self.config)
         }
@@ -203,7 +214,7 @@ impl<'a, 'b> PathSource<'a, 'b> {
     {
         let mut ret = Vec::new();
         for pkg in self.packages.iter().filter(|p| *p == pkg) {
-            let loc = pkg.manifest_path().parent().unwrap();
+            let loc = pkg.root();
             try!(walk(loc, &mut ret, true, &mut filter));
         }
         return Ok(ret);
index 9fe689b133de3993879b1c089d97779675239774..ad6aff16e3ea7e398226170402eb60ad579fb40c 100644 (file)
@@ -22,3 +22,9 @@ impl<'a> ToSemver for &'a String {
         (**self).to_semver()
     }
 }
+
+impl<'a> ToSemver for &'a Version {
+    fn to_semver(self) -> Result<Version, String> {
+        Ok(self.clone())
+    }
+}